---@class GT.ui.model.selectUi 选中UI
GT.ui.model.selectUi = class()

---@class selectUi_data 选中UI
---@field icon number 图标
---@field icon_select number 选中图标
---@field x number
---@field y number
---@field parent GT.ui 父UI
---@field click UI_EVENT 点击
---@field enter UI_EVENT 进入
---@field leave UI_EVENT 离开
---@field show boolen 显示

---@param d selectUi_data
function GT.ui.model.selectUi:ctor(d)
    self.ui = {}
    self.prefab = {}
    self.prefab["选择UI"] = GT.ui.prefab.obj({
        module = "2fa0676d-8c61-4610-b83b-98b83b62855b",
        parent = d.parent.uid,
    })
    local p = self.prefab["选择UI"]
    self.ui["self"] = p:child(GT.ui.control.image, "选择UI")
    self.id=self.ui["self"].uid
    self.ui["选中UI"] = p:child(GT.ui.control.image, "选中UI")
    self.ui["选择提示"] = p:child(GT.ui, "选择提示")

    self.ui["self"].binding.img = d.icon
    self.ui["self"].binding.x = d.x
    self.ui["self"].binding.y = d.y

    self.ui["选中UI"].binding.img = d.icon_select

    self.ui["self"]:click(function (data, player, ui)
        d.click(data, player, self)
    end)
    self.ui["self"]:enter(function (data, player, ui)
        self.ui["选中UI"].u[player.pid].binding.show = true
        d.enter(data, player, self)
    end)
    self.ui["self"]:leave(function(data, player, ui)
        self.ui["选中UI"].u[player.pid].binding.show = false
        d.leave(data, player, self)
    end)
    self.ui["self"].binding.show=d.show
    self:tip()
end

function  GT.ui.model.selectUi:tip()
    local p = self.prefab["选择UI"]
    
    self.ui["name"] = p:child(GT.ui.control.label, "选择提示.name")
    self.ui["lv"] = p:child(GT.ui.control.label, "选择提示.lv")
    self.ui["icon"] = p:child(GT.ui.control.image, "选择提示.skill.icon")
    self.ui["cd"] = p:child(GT.ui.control.label, "选择提示.cd")

    self.ui["金币背景"] = p:child(GT.ui.control.image, "选择提示.金币")
    self.ui["人口背景"] = p:child(GT.ui.control.image, "选择提示.人口")

    self.ui["金币"] = p:child(GT.ui.control.label, "选择提示.金币.cost")
    self.ui["人口"] = p:child(GT.ui.control.label, "选择提示.人口.cost")

    self.ui["text"] = p:child(GT.ui.control.label, "选择提示.des.text")
    self.ui["des"] = p:child(GT.ui.control.scroll_view, "选择提示.des")
end

---设置tip信息
---@param p GT.player
---@param data buildAbilityTip_data
function GT.ui.model.selectUi:set(p, data)
    self.ui["text"].u[p.pid].binding.text = data.text
    self.ui["name"].u[p.pid].binding.text = data.name
    self.ui["lv"].u[p.pid].binding.text = "Lv." .. data.lv
    self.ui["icon"].u[p.pid].binding.img = data.icon
    
    self.ui["cd"].u[p.pid].binding.text = ""

    local gold =data.gold or 0
    if gold>0 then
        self.ui["金币背景"].u[p.pid].binding.show=true
        self.ui["金币"].u[p.pid].binding.text = data.gold or 0
    else
        self.ui["金币背景"].u[p.pid].binding.show=false
    end

    local pop=data.pop or 0

    if pop>0 then
        self.ui["人口背景"].u[p.pid].binding.show=true
        self.ui["人口"].u[p.pid].binding.text = data.pop or 0
    else
        self.ui["人口背景"].u[p.pid].binding.show=false
    end
    self:show(p)
end




---显示
---@param p GT.player
function GT.ui.model.selectUi:show(p)
    if p ~= nil then
        self.ui["选择提示"].u[p.pid].binding.show = true
    else
        self.ui["选择提示"].binding.show = true
    end
end

---隐藏
function GT.ui.model.selectUi:hide(p)
    if p ~= nil then
        self.ui["选择提示"].u[p.pid].binding.show = false

    else
        self.ui["选择提示"].binding.show = false
    end
end


---@param data selectUi_data
---@return GT.ui.model.selectUi
function GT.ui.model.selectUi.obj(data)
    return new(GT.ui.model.selectUi, data)
end
